package com.ytx.flutter_ytx_plugin.x5

import android.content.Context
import android.content.Intent
import com.ytx.flutter_ytx_plugin.X5Request
import com.ytx.flutter_ytx_plugin.X5Response
import io.flutter.plugin.common.BinaryMessenger


class X5Web(
    private val context: Context,
    private val x5Response: X5Response,
    private val messenger: BinaryMessenger
) : X5Request {
    init {
        X5Request.setUp(messenger, this)
    }

    override fun initX5Sdk() = X5ApiHandler.setup(context, x5Response);

    override fun openWebActivity(map: Map<String, Any>?) {
        val url = map?.get("url")
        val title = map?.get("title")
        val headers = map?.get("headers")
        val isUrlIntercept = map?.get("isUrlIntercept")
        val intent = Intent(context, X5WebViewActivity::class.java)
        intent.putExtra("url", "$url");
        intent.putExtra("title", "$title")
        intent.putExtra("headers", headers as? HashMap<*, *> ?: HashMap<String, String>())
        intent.putExtra("isUrlIntercept", isUrlIntercept as? Boolean ?: true)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)
    }

    override fun openVideo(map: Map<String, Any>) {}
    override fun openFile(map: Map<String, Any>) {}
    override fun setDownloadWithoutWifi(map: Map<String, Any>) {}
    override fun loadUrl(url: String, headers: Map<String, Any>?) {}
    override fun reload() {}
    override fun canGoBack() {}
    override fun canGoForward() {}
    override fun goBack() {}

    override fun goForward() {}
    override fun goBackOrForward(point: Long) {}
    override fun currentUrl(): String = ""

    override fun evaluateJavascript(map: Map<String, Any>) {}

    override fun addJavascriptChannels(map: Map<String, Any>) {}


}